package one.stand.enums;

import java.util.Map;
import java.util.Objects;

/**
 * @author zrh
 */

public enum OrderStateEnum {

    BE_OVERDUE(0, "已过期"),
    WAIT_PAYMENT(1, "待付款"),
    WAIT_DELIVER(2, "待发货"),
    WAIT_RECEIVING(3, "待收货"),
    COMPLETE(4, "已完成"),
    CANCEL(5, "交易取消"),
    REFUND_SUCCESS(6, "退款成功");

    private Integer code;
    private String message;

    OrderStateEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    private static Map<Integer, OrderStateEnum> map = EnumUtil.getEnumMap(values(), OrderStateEnum::getCode);

    public static OrderStateEnum fromMap(Integer suffix) {
        return map.get(suffix);
    }

    public static String getMessage(Integer code) {
        OrderStateEnum stateEnum = fromMap(code);
        return Objects.nonNull(stateEnum) ? stateEnum.getMessage() : null;
    }
}
